<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/31
 * Time: 9:22
 */

namespace app\api\validate;


use app\lib\exception\BaseException;
use think\Validate;

class OrderPlace extends BaseValidate
{

    protected $rule = [
        'products'=>'checkProducts'
    ];

    protected $singleRule = [
        'product_id' => 'require|isPositiveInteger',
        'count' => 'require|isPositiveInteger',
    ];

    public function checkProducts($values){
        if(empty($values)){
            throw new BaseException([
                'msg' => '商品列表不能为空'
            ]);
        }
        foreach ($values as $value){
            $this->checkProduct($value);
        }
        return true;

    }

    public function checkProduct($value){
        $validate = new Validate($this->singleRule);
        if($validate->check($value)){
            throw new BaseException([
                'msg' => '商品列表参数错误',
            ]);
        }
    }

}